package com.gexiaobao.pigeon.ui.adapter

import android.graphics.Color
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.ShedPigeonListResponse
import com.gexiaobao.pigeon.databinding.ItemPigoenShedInfoBinding

/**
 * @Author      : hxw
 * @Date        : 2024/5/6 15:47
 * @Describe    :
 */
class PigeonShedListAdapter(data: ArrayList<ShedPigeonListResponse.ListData>) :
    BaseQuickAdapter<ShedPigeonListResponse.ListData, DataBindBaseViewHolder>(R.layout.item_pigoen_shed_info, data) {
    override fun convert(holder: DataBindBaseViewHolder, item: ShedPigeonListResponse.ListData) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemPigoenShedInfoBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val tvPair = holder.getView<AppCompatTextView>(R.id.tv_shed_pair)
        if (item.ringSn.isEmpty()) {
            tvPair.text = context.getString(R.string.hint_pair)
            tvPair.background = ContextCompat.getDrawable(context, R.drawable.round_btn_light_red5_bg)//round_btn_red10_b_g
        } else {
            tvPair.text = context.getString(R.string.copyreader)
            tvPair.background = ContextCompat.getDrawable(context, R.drawable.round_btn_blue5_bg)
        }

        if (item.loftPicPath.isEmpty()) {
            holder.setText(R.id.tvItemShedInfoPic, context.getString(R.string.unbeaten))
            holder.setTextColor(R.id.tvItemShedInfoPic, ContextCompat.getColor(context, R.color.color_f65a5a))
        } else {
            holder.setText(R.id.tvItemShedInfoPic, context.getString(R.string.beaten))
            holder.setTextColor(R.id.tvItemShedInfoPic, ContextCompat.getColor(context, R.color.color_003366))
        }

        val ringId = item.ringId
        if (ringId.isNotEmpty() && ringId.contains("-")) {
            val ringSplit = ringId.split("-")
            val result = when (ringSplit.size) {
                3 -> {
                    ringSplit[0] + "-" + ringSplit[1] + "-\n" + ringSplit[2]
                }

                2 -> {
                    ringSplit[0] + "-" + ringSplit[1]
                }

                1 -> {
                    ringSplit[0]
                }

                else -> {
                    "--"
                }
            }
            holder.setText(R.id.tvItemShedInfoRing, result)
        }
    }
}